package com.snail.test.utils;

import io.github.biezhi.wechat.WeChatBot;
import io.github.biezhi.wechat.api.WeChatApi;
import io.github.biezhi.wechat.api.WeChatApiImpl;
import io.github.biezhi.wechat.api.annotation.Bind;
import io.github.biezhi.wechat.api.constant.Config;
import io.github.biezhi.wechat.api.enums.MsgType;
import io.github.biezhi.wechat.api.model.WeChatMessage;
import io.github.biezhi.wechat.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: TODO
 */
@Slf4j
public class HelloBot extends WeChatBot {

    public HelloBot(Config config) {
        super(config);
    }

    @Bind(msgType = MsgType.ALL)
    public void handleText(WeChatMessage message) {
        if (StringUtils.isNotEmpty(message.getName())) {
            log.info("接收到 [{}] 的消息: {}", message.getName(), message.getText());
            this.sendMsg(message.getFromUserName(), "自动回复: " + message.getText());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        HelloBot helloBot = new HelloBot(Config.me().autoLogin(true).showTerminal(true));

        Thread t1 = new Thread(() -> {
            helloBot.start();
        });
        t1.start();
        Thread.sleep(10000);
        WeChatApi weChatApi = new WeChatApiImpl(helloBot);
        System.out.println("开始发送信息");
//        weChatApi.sendText("文件传输助手", "test");
        helloBot.sendMsg("文件传输助手", "test");
        System.out.println("信息发送成功");
    }

}